package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import pojo.Bill;
import pojo.Provider;
import pojo.User;
import service.BillService;
import service.ProviderService;
import service.UserService;
import tools.Constants;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("/bill")
public class BillController {

    @Resource
    private BillService billService;
    @Resource
    private ProviderService providerService;

    @RequestMapping("/billlist.html")
    public String billList(@RequestParam(value = "queryProductName",required = false) String queryProductName,
                           @RequestParam(value = "queryProviderId",required = false) String queryProviderId,
                           @RequestParam(value = "queryIsPayment",required = false) Integer queryIsPayment,Model model){
        if (queryProductName==null){
            queryProductName="";
        }
        if (queryProviderId==null){
            queryProviderId="";
        }
        if (queryIsPayment==null){
            queryIsPayment=0;
        }
        Bill bill=new Bill();
        bill.setProductName(queryProductName);
        bill.setProviderName(queryProviderId);
        bill.setIsPayment(queryIsPayment);


        model.addAttribute("queryProductName",queryProductName);
        model.addAttribute("queryIsPayment",queryIsPayment);
        model.addAttribute("queryProviderId",queryProviderId);
        model.addAttribute("providerList",providerService.getProviderList());
        model.addAttribute("billList",billService.getBillList(bill));

        return "billlist";
    }

    @RequestMapping("billadd.html")
    public String billadd(){
        return "billadd";
    }
}
